<?php

namespace Admin\Controller;

class QuestionController extends CommonController
{
    // 列表
    public function lists()
    {
        $key     = I('request.key', '', 'trim');
        $audit   = I('request.audit', '', 'trim');
        $issolve = I('request.issolve', '', 'trim');
        $sort    = 'id DESC';

        $map = array();
        if ($key) {
            $key_type = I('request.key_type', 0, 'intval');
            // keyword map
            $map = array_merge($map, D('Question')->map_keywords($key, $key_type));
        }
        if ($audit <> '') {
            $map['audit'] = intval($audit);
        }
        if ($issolve <> '') {
            $map['issolve'] = intval($issolve);
        }

        $list = D('Question')->get_list($map, true, $sort, 10);

        $this->assign('lists', $list);

        $this->display();
    }

    // 修改审核
    public function audit()
    {
        $ids   = I('request.id');
        $audit = I('request.audit', '0', 'intval');

        $ids = is_array($ids) ? implode(",", $ids) : $ids;
        if ($ids && is_match_ids($ids)) {
            D('Question')->question_audit($audit, $ids);
            $this->success("设置成功！");
        } else {
            $this->error('请选择项目！');
        }

    }

    // 后台删除问题
    public function delete()
    {
        $ids = I('request.id');
        $ids = is_array($ids) ? implode(",", $ids) : $ids;
        if ($ids && is_match_ids($ids)) {
            D("Question")->del_question($ids);
            $this->success("成功删除");
        } else {
            $this->error('请选择要删除的信息！');
        }
    }
}